package com.hellogood.yaohuo.server.mgr;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hellogood.yaohuo.server.dao.factory.DAOFactory;
import com.hellogood.yaohuo.shared.entity.Kc;
import com.hellogood.yaohuo.shared.vo.KcVo;

public class KcMgr {
	public List<Kc> getKcBy(String orgCode, String pluCode, String bra, String color, String size) {
		return DAOFactory.getInstance().createKcDAO().getKcBy(orgCode, pluCode, bra, color, size);
	}

	public List<KcVo> searchKC(String orgCode, String code, int page, int pageSize) {
		// "编码", "条码", "部门", "品类", "颜色", "尺寸", "数量", "进价金额", "售价金额"
		return DAOFactory.getInstance().createKcDAO().searchKcVoByPage(orgCode, code, page, pageSize);
	}

	public int getTotalCount(String orgCode, String code) {
		return DAOFactory.getInstance().createKcDAO().searchKCTotalNumber(orgCode, code);
	}

	public int getKcCounts4YaohuoBy(String orgCode, String pluCode, String bra, String color) {
		List<Kc> kcs = DAOFactory.getInstance().createKcDAO().getKc(orgCode, pluCode, bra, color);
		int counts = 0;
		if (kcs != null && kcs.size() > 0) {
			for (Kc kc : kcs) {
				counts += kc.getCounts();
			}
		}
		return counts;
	}

	public Map<Integer, Integer> getKc(String orgCode, String pluCode, String bra, String color) {
		List<Kc> kcs = DAOFactory.getInstance().createKcDAO().getKc(orgCode, pluCode, bra, color);
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i = 0; i < 7; i++) {
			int has = 0;
			for (Kc kc : kcs) {
				if (kc.getColor().equals(String.valueOf(i))) {
					has = kc.getCounts();
				}
			}
			map.put(i, has);
		}
		return map;
	}
}
